package edu.uafs.museum;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.location.LocationManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class ExhibitionListAdapter extends android.widget.ArrayAdapter<Exhibition> {
	
	ArrayList<Exhibition> exhibitions;
	
	Context context;
	
	int layoutResourceID;
	
	public ExhibitionListAdapter(Context context, int resource, ArrayList<Exhibition> exhibitions)
	{
		super(context, resource, exhibitions);
		this.context = context;
		this.exhibitions = exhibitions;
		this.layoutResourceID = resource;
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return exhibitions.size();
	}

	public Exhibition getItem(int position) {
		// TODO Auto-generated method stub
		return exhibitions.get(position);
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		
		//get the exhibition
		Exhibition exhibition = (Exhibition)exhibitions.get(position);
		
		View view = convertView;
		
		if (convertView == null)
		{
			LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            view = inflater.inflate(layoutResourceID, parent, false);
			
			ImageView iv = (ImageView)view.findViewById(R.id.exhibitionImage);
			TextView id = (TextView)view.findViewById(R.id.id);
			TextView name = (TextView)view.findViewById(R.id.name);
			TextView link = (TextView)view.findViewById(R.id.link);
			TextView description = (TextView)view.findViewById(R.id.description);
			
			if (exhibition.getImage_bitmap() != null)
				iv.setImageBitmap(exhibition.getImage_bitmap());
			
			id.setText(exhibition.getID());
			name.setText(exhibition.getName());
			link.setText(exhibition.getLink());
			description.setText(exhibition.getDescription());
		}
		
		return view;
	}

}
